gdk/wayland: Use last press serial for clipboard/primary selections
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 18 Jul 2022 10:46:11 +0000 (12:46 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 18 Jul 2022 11:01:27 +0000 (13:01 +0200)
This serial observes key and button presses, we can use that instead
of relying on the last serial which might come from other
events/devices.

gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkprimary-wayland.c

index 2d192f8550f9e2c2259ab84fb5037a42ff4b81f4..04bf0aa216196a0f945001cce3af698ec8631ecc 100644 (file)
@@ -5305,15 +5305,13 @@ gdk_wayland_device_set_selection (GdkDevice             *gdk_device,
                                   struct wl_data_source *source)
 {
   GdkWaylandSeat *seat;
-  GdkWaylandDisplay *display_wayland;
+  guint32 serial;
 
   g_return_if_fail (GDK_IS_WAYLAND_DEVICE (gdk_device));
 
   seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (gdk_device));
-  display_wayland = GDK_WAYLAND_DISPLAY (seat->display);
-
-  wl_data_device_set_selection (seat->data_device, source,
-                                _gdk_wayland_display_get_serial (display_wayland));
+  serial = _gdk_wayland_seat_get_implicit_grab_serial (GDK_SEAT (seat), NULL);
+  wl_data_device_set_selection (seat->data_device, source, serial);
 }
 
 /**
index b8e0ff40fdfdc894331ddffffc8d556d9e64d002..7aa702bef80ff38bbde0bb7ae9920f2e2699e7f5 100644 (file)
@@ -263,6 +263,8 @@ gdk_wayland_primary_claim (GdkClipboard       *clipboard,
       GdkWaylandDisplay *wdisplay = GDK_WAYLAND_DISPLAY (gdk_clipboard_get_display (clipboard));
       const char * const *mime_types;
       gsize i, n_mime_types;
+      GdkSeat *seat;
+      guint32 serial;
 
       gdk_wayland_primary_discard_offer (cb);
       gdk_wayland_primary_discard_source (cb);
@@ -276,9 +278,11 @@ gdk_wayland_primary_claim (GdkClipboard       *clipboard,
           zwp_primary_selection_source_v1_offer (cb->source, mime_types[i]);
         }
 
+      seat = gdk_display_get_default_seat (GDK_DISPLAY (wdisplay));
+      serial = _gdk_wayland_seat_get_implicit_grab_serial (seat, NULL);
       zwp_primary_selection_device_v1_set_selection (cb->primary_data_device,
                                                      cb->source,
-                                                     _gdk_wayland_display_get_serial (wdisplay));
+                                                     serial);
     }
 
   return GDK_CLIPBOARD_CLASS (gdk_wayland_primary_parent_class)->claim (clipboard, formats, local, content);